#!/bin/sh
#
# An example hook script to verify what is about to be committed.
# Called by "git commit" with no arguments.  The hook should
# exit with non-zero status after issuing an appropriate message if
# it wants to stop the commit.
#
# To enable this hook, rename this file to "pre-commit".
echo '....................................check code start'
GOOGLE_CHECK='../mbs/checkstyle/google_checks.xml'
CHECK_STYLE='../mbs/checkstyle/checkstyle-8.14-all.jar'
i=0;
for file in $(git diff --name-only --cached \*.java); do
 CALL_BACK[$i]=$(echo $(java -jar $CHECK_STYLE -c $GOOGLE_CHECK $file))
  let i++ 
done
#JAVA_COMMEND=$(java -jar $CHECK_STYLE -c $GOOGLE_CHECK #E:/app-cms/cms-api/src/main/java/com/baoyinxiaofei/cms/dto/versionCompatibilityDTO.java)
#echo $JAVA_COMMEND
echo ${CALL_BACK[@]}
echo '....................................check code end'
if [[ "${CALL_BACK[@]}" =~ "[WARN]" ]]
then
echo '..........................代码必须checkstyle之后才能提交的'
exit 1
else
echo '.................................代码检查完成提交'
fi

